package com.ogilvy.audi.dao.hibernate;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.ogilvy.audi.dao.CircleCategoryDao;
import com.ogilvy.audi.model.CircleCategory;

@Repository("circleCategoryDao")
public class CircleCategoryDaoHibernate extends GenericDaoHibernate<CircleCategory, Long> implements CircleCategoryDao {

    public CircleCategoryDaoHibernate() {
        super(CircleCategory.class);
    }
    public List<CircleCategory> query(Map<String,Object> condition){
    	StringBuffer hql = new StringBuffer("from CircleCategory where 1=1");
		if(condition.get("parentId")!=null){
			hql.append(" and parentId =").append(condition.get("parentId"));
		}
		if(condition.get("isHot")!=null){
			hql.append(" and isHot =").append(condition.get("isHot"));
		}
		if(condition.get("isNew")!=null){
			hql.append(" and isNew =").append(condition.get("isNew"));
		}
		return this.getSessionFactory().getCurrentSession().
		 createQuery(hql.toString()).list();
    }
    public List<CircleCategory> queryByHot(){
    	return this.getSessionFactory().getCurrentSession().createQuery("from CircleCategory where isHot = 1").list();
    }
}
